package ink.lovejinhu.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jinhu
 * created 2021-08-04 10:24
 */
public class Solution_0728 {
    /**
     * 自除数
     *
     * @param left
     * @param right
     * @return
     */
    public List<Integer> selfDividingNumbers(int left, int right) {
        ArrayList<Integer> res = new ArrayList<>();
        for (int i = left; i <= right; i++) {

            if (this.isMatch(i)) {
                res.add(i);
            }
        }
        return res;
    }

    public boolean isMatch(int param) {
        String temp = param + "";
        for (int i = 0; i < temp.length(); i++) {
            if (temp.charAt(i) == '0') return false;
            if (param % (temp.charAt(i) - '0') != 0) {
                return false;
            }
        }
        return true;
    }
}
